package com.fand.manager.model.operate;

import java.util.Date;
import java.util.Objects;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.date.DateUtil;
import com.fand.common.model.BaseDTO;
import com.fand.common.util.JsonUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Author: zhangjiabin
 * Email: javaboyok@163.com
 * CreateDate: 2021/6/27
 * Version: 1.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SysUserOperateSearchDTO extends BaseDTO {

    private String userName;
    private String userCode;

    private String requestURI;

    private String dateTime;

    public SysUserOperateSearchDTO builder() {
        if (Objects.isNull(getSearchParams())) {
            this.setDateTime(DateUtil.formatDate(new Date()));
            return this;
        } else {
            SysUserOperateSearchDTO sysUserOperateSearchDTO = JsonUtils.jsonToPojo(JsonUtils.objectToJson(JsonUtils.jsonToPojo(getSearchParams(), SysUserOperateSearchDTO.class)), SysUserOperateSearchDTO.class);
            CopyOptions copyOptions = CopyOptions.create();
            copyOptions.setIgnoreNullValue(true);

            sysUserOperateSearchDTO.setDateTime(sysUserOperateSearchDTO.getDateTime() == null ? DateUtil.formatDate(new Date()):sysUserOperateSearchDTO.getDateTime());

            BeanUtil.copyProperties(sysUserOperateSearchDTO, this, copyOptions);
            return this;
        }
    }
}
